Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local register index and state re-execution #553

Closed
wants to merge 187 commits into from
Closed

Conversation

sideninja
Copy link
Contributor

@sideninja sideninja commented Sep 16, 2024

Closes: #322 #450 #451 #452

Includes PRs
#550
#546
#542
#541
#540
#537

This is a feature branch that contains work from multiple PRs to implement local register index along with the state re-execution.

It's still in draft because further testing is needed and we should also include the checksum to validate the local state after each transaction is executed, that is depending on the PR onflow/flow-go#6456 those checksum should be used to validate the state instead of the receipt checking which is currently done.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

Release Notes

  • New Features

    • Simplified naming conventions for network environments in the documentation (e.g., "EVM on Flow Testnet" to "Testnet").
    • Introduced a ClientHandler for managing EVM operations, enhancing local and remote client interactions.
    • Added a State field in the Bootstrap struct for state indexing management.
    • Enhanced functionality of the BlockState for robust transaction execution and state management.
    • Implemented a state engine for processing blockchain blocks, improving state management capabilities.
  • Bug Fixes

    • Improved error handling in transaction receipt retrieval and block height resolution.
  • Documentation

    • Updated README to reflect changes in network naming conventions.
  • Tests

    • Added comprehensive unit tests for the handleCall function to validate local and remote call handling.
  • Chores

    • Updated various dependencies in the go.mod file for improved functionality and stability.

# Conflicts:
#	models/receipt.go
#	models/transaction.go
# Conflicts:
#	bootstrap/bootstrap.go
#	go.mod
#	go.sum
#	models/receipt.go
#	models/transaction.go
#	tests/go.mod
#	tests/go.sum
#	tests/helpers.go
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
services/requester/remote_client.go (1)

Line range hint 104-194: Consider refactoring the function into smaller, focused functions.

The NewRemote function is quite lengthy and performs multiple responsibilities, such as verifying the COA account balance, creating an emulator configuration, setting up a cache, and creating a COA resource. Consider extracting these responsibilities into separate functions for better readability and maintainability.

services/requester/client_handler_test.go (1)

40-42: Refactor repeated logger initialization into a helper function.

The logger initialization code is duplicated across multiple test functions. Consider refactoring it into a helper function to reduce code duplication and enhance maintainability.

Add a helper function at the beginning of the file:

func newTestLogger(buf *bytes.Buffer) zerolog.Logger {
	return zerolog.New(buf).With().Timestamp().Logger()
}

Then, replace the logger initialization in each test function:

-var buf bytes.Buffer
-logger := zerolog.New(&buf).With().Timestamp().Logger()
+var buf bytes.Buffer
+logger := newTestLogger(&buf)

Also applies to: 62-64, 84-86, 106-108, 128-130, 150-152, 172-174, 195-197, 218-220, 241-243

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6e24eb6 and 11833eb.

Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • tests/go.sum is excluded by !**/*.sum
Files selected for processing (5)
  • go.mod (1 hunks)
  • services/requester/client_handler.go (1 hunks)
  • services/requester/client_handler_test.go (1 hunks)
  • services/requester/remote_client.go (25 hunks)
  • tests/go.mod (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • go.mod
  • services/requester/client_handler.go
  • tests/go.mod
Additional comments not posted (14)
services/requester/remote_client.go (14)

Line range hint 85-102: LGTM!

The RemoteClient struct is well-defined with appropriate fields for its functionality.


Line range hint 196-253: LGTM!

The SendRawTransaction function performs appropriate validations on the EVM transaction, handles errors, and correctly builds and sends the Flow transaction.


Line range hint 255-303: LGTM!

The buildTransaction function correctly creates a Flow transaction with the provided script and arguments, sets the necessary transaction fields, and signs it with the configured COA account. The use of concurrency to retrieve the latest block and signer network information is a good optimization.


Line range hint 305-345: LGTM!

The GetBalance function correctly retrieves the balance of an EVM address at a specific EVM height by executing a Cadence script. It performs the necessary type conversions and handles errors appropriately.


Line range hint 347-394: LGTM!

The GetNonce function correctly retrieves the nonce of an EVM address at a specific EVM height by executing a Cadence script. It performs the necessary type conversions and handles errors appropriately.


Line range hint 396-421: LGTM!

The stateAt function correctly retrieves the EVM state at a specific EVM height by creating a remote ledger and a new state database. It performs the necessary height conversion and handles errors appropriately.


Line range hint 423-431: LGTM!

The GetStorageAt function correctly retrieves the storage value of an EVM address at a specific EVM height and storage hash. It uses the stateAt function to retrieve the state database and handles errors appropriately.


Line range hint 433-482: LGTM!

The Call function correctly executes an EVM call at a specific EVM height by executing a Cadence script. It performs the necessary type conversions and handles errors appropriately.


Line range hint 484-538: LGTM!

The EstimateGas function correctly estimates the gas consumption of an EVM transaction at a specific EVM height by executing a Cadence script. It performs the necessary type conversions and handles errors appropriately.


Line range hint 540-588: LGTM!

The GetCode function correctly retrieves the code of an EVM address at a specific EVM height by executing a Cadence script. It performs the necessary type conversions and handles errors appropriately.


Line range hint 590-614: LGTM!

The GetLatestEVMHeight function correctly retrieves the latest EVM height by executing a Cadence script. It handles errors appropriately and returns the result as a uint64.


Line range hint 616-641: LGTM!

The getSignerNetworkInfo function correctly retrieves the signer account information from the network and returns the key index and sequence number of the signer. It handles errors appropriately and returns informative error messages.


Line range hint 643-661: LGTM!

The replaceAddresses function correctly replaces the import statements and COA address in the provided script based on the network configuration. It retrieves the system contracts for the configured Flow network ID and replaces the addresses appropriately.


663-669: LGTM!

The evmToCadenceHeight function correctly converts an EVM height to a Cadence height using the blocks storage. It handles errors appropriately and returns informative error messages.

Comment on lines +25 to +27
func containsLogMessage(logOutput, message string) bool {
return bytes.Contains([]byte(logOutput), []byte(message))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the unused helper function containsLogMessage.

The function containsLogMessage is defined but not used anywhere in the code. Removing unused code helps improve maintainability and readability.

Apply this diff to remove the unused function:

-// Helper function to check if log output contains a specific message
-func containsLogMessage(logOutput, message string) bool {
-	return bytes.Contains([]byte(logOutput), []byte(message))
-}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func containsLogMessage(logOutput, message string) bool {
return bytes.Contains([]byte(logOutput), []byte(message))
}

@sideninja sideninja marked this pull request as draft September 25, 2024 10:02
@sideninja sideninja changed the title Local state index Local register index and state re-execution Sep 25, 2024
@m-Peter
Copy link
Collaborator

m-Peter commented Nov 4, 2024

Closing in favor of: #635

@m-Peter m-Peter closed this Nov 4, 2024
@m-Peter m-Peter deleted the feature/state branch November 4, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Local register index and state re-execution
2 participants